<!--  -->
<template>
  <div class="productadd">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/admin/main' }"
        >首页</el-breadcrumb-item
      >
      <el-breadcrumb-item
        ><a href="javascript:;">产品管理</a></el-breadcrumb-item
      >
      <el-breadcrumb-item>添加产品</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-form label-width="100px">
        <el-form-item label="分类">
          <el-cascader
            v-model="options.label"
            :options="options"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="productData.title"></el-input>
        </el-form-item>
        <el-form-item label="是否可用" prop="is_show">
          <el-switch
            v-model="value"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="可用"
            inactive-text="禁用"
          ></el-switch>
          <!-- active-value="1"
            inactive-value="0"
            active-text="可用"
            inactive-text="禁用" -->
        </el-form-item>
        <el-form-item label="图片">
          <!-- <el-upload
            class="avatar-uploader"
            action="http://192.168.1.64:4000/api/admin/uploadimg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img
              v-if="imageUrl"
              :src="'http://192.168.1.64:4000/' + imageUrl"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload> -->
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      //   value: [],
      imageUrl: "",
      options: [
        {
          value: "家用电器",
          label: "家用电器",
          children: [
            {
              value: "大家电",
              label: "大家电",
            },
            {
              value: "厨房电器",
              label: "厨房电器",
            },
          ],
        },
        {
          value: "男装女装",
          label: "男装女装",
          children: [
            {
              value: "男装",
              label: "男装",
            },
            {
              value: "女装",
              label: "女装",
            },
            {
              value: "户外运动",
              label: "户外运动",
            },
          ],
        },
      ],
      value: true,
      productData: {
        title: "",
        is_show: "",
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    handleChange(value) {
      console.log(value);
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
  },

  mounted() {},
};
</script>
<style lang="less">
.productadd {
  .el-card {
    margin-top: 15px;
    .el-form {
      width: 400px;
    }
  }
}
</style>